home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ncsa / Mac / Telnet2.6 / prerelease / d5 / Telnet 2.6.1d5.src.sit.hqx / Telnet 2.6.1d5 src / source / main / menuseg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-22  |  38.6 KB  |  1,425 lines

  1. /****************************************************************
  2. *    NCSA Telnet for the Macintosh                                *
  3. *                                                                *
  4. *    National Center for Supercomputing Applications                *
  5. *    Software Development Group                                    *
  6. *    152 Computing Applications Building                            *
  7. *    605 E. Springfield Ave.                                        *
  8. *    Champaign, IL  61820                                        *
  9. *                                                                *
  10. *    Copyright (c) 1986-1992,                                    *
  11. *    Board of Trustees of the University of Illinois                *
  12. *****************************************************************
  13. *
  14. *    Menu Handling and initialization code.
  15. *
  16. *    
  17. *    Revisions:
  18. *    7/92 Telnet 2.6 initial version: reorganized defines, put all stray globals in a struct, and
  19. *                put all cursors in a nice array.  Moved some routines to other places -    Scott Bulmahn            
  20. *
  21. *    6/94 Added support for Keypad and Function menus - Carl Bell (Baylor U.)
  22. */
  23.  
  24. #ifdef MPW
  25. #pragma segment 4
  26. #endif
  27.  
  28. #include    <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31.  
  32. #include "TelnetHeader.h"
  33. #include "menu_resrcdefs.h"
  34. #include "dialog_resrcdefs.h"
  35. #include "string_resrcdefs.h"
  36. #include    "wind.h"
  37. #include "menuseg.proto.h"
  38. #include "mainseg.proto.h"
  39. #include "Sets.proto.h"                /* JMB: For Saved Sets functions */
  40. #include    "configure.proto.h"
  41. #include "parse.proto.h"
  42. #include "InternalEvents.h"
  43. #include "mydnr.proto.h"
  44. #include "rsinterf.proto.h"
  45. #include "network.proto.h"
  46. #include "maclook.proto.h"
  47. #include "vrrgmac.proto.h"
  48. #include "rgmp.proto.h"
  49. #include "tekrgmac.proto.h"
  50. #include "vgtek.proto.h"
  51. #include "netevent.proto.h"
  52. #include "Connections.proto.h"
  53.  
  54. #include "vsdata.h"
  55. #include "vsinterf.proto.h"
  56.  
  57. #include "event.proto.h"
  58. #include "macros.proto.h"
  59. #include "DlogUtils.proto.h"            /* For VersionNumber, OutlineItem, and DialogProc Protos */
  60. #include "telneterrors.h"
  61. #include "debug.h"
  62.  
  63. #include <Printing.h>
  64. #include "printing.proto.h"
  65. #include "menuseg.proto.h"
  66. #include "translate.proto.h"
  67. #include "parse.proto.h"                // For SendNAWSinfo proto
  68. #include "keypadmenus.proto.h"
  69.  
  70. MenuHandle
  71.     myMenus[NMENUS];        /* Menu Handles .... */
  72.  
  73. //char *tempspot;                /* temporary storage ~255 bytes malloc-ed */
  74.  
  75.  
  76. /*
  77.  * External variable declarations (those which we borrow )
  78.  *
  79.  */
  80. extern short scrn;
  81. extern Cursor *theCursors[];
  82. extern WindRec
  83.     *screens,            /* The screen array from Maclook */
  84.     *ftplog;                    /* The FTP log screen from Maclook */
  85. extern SysEnvRec theWorld;                        /* System Environment record */
  86. extern    short    nNational;
  87.  
  88. void CloseCaptureFile(short w)
  89. {
  90.     VSclosecapture(w);                                /* BYU 2.4.18 */
  91.     CheckItem(myMenus[Emul], EMcapture,FALSE);        /* BYU 2.4.18 */
  92. }
  93.  
  94. /*    portsOpen()    - Count the number of ports open. Returns 3 different answers
  95.  *                  0= no ports at all, 1= at least active, -1= ports/none active. */
  96. short    portsOpen(void)
  97. {
  98.     short pnum;
  99.  
  100.     pnum=TelInfo->numwindows-1;
  101.     if (pnum<0)  return(0);
  102.     while (pnum>=0) 
  103. //        if (!screens[pnum--].active && !screens[pnum+1].corpse) return(1);
  104.         // corpse status now part of active flag
  105.         if (screens[pnum--].active == CNXN_ACTIVE) return(1);
  106.     return(-1);
  107. }
  108.  
  109. void    AdjustMenus(void)
  110. {
  111.     short        i;
  112.     WindowPtr    wind;
  113.     
  114.     if ((wind = FrontWindow()) != NULL && (((WindowPeek)wind)->windowKind >= userKind))
  115.         EnableItem( myMenus[Fil],FLclose);
  116.     else
  117.         DisableItem( myMenus[Fil],FLclose);
  118.         
  119.     if ((i=portsOpen()) <1) {
  120.         DisableItem( myMenus[Fil],FLsave);
  121.         DisableItem( myMenus[Fil],FLprint);
  122.         DisableItem( myMenus[Edit],EDcut);
  123.         DisableItem( myMenus[Edit],EDundo);
  124.         DisableItem( myMenus[Edit],EDclear);
  125.         DisableItem( myMenus[Edit],EDcopy);
  126.         DisableItem( myMenus[Edit],EDcopyt);
  127.  
  128.  
  129.         DisableItem( myMenus[Emul],EMbs);
  130.         DisableItem( myMenus[Emul],EMdel);
  131.         DisableItem( myMenus[Emul],EMecho);
  132.         DisableItem( myMenus[Emul],EMwrap);
  133.         DisableItem( myMenus[Emul],EMscroll);
  134.         DisableItem( myMenus[Emul],EMreset);
  135.         DisableItem ( myMenus[Emul],EMjump);
  136.         DisableItem ( myMenus[Emul],EMpage);
  137.         DisableItem ( myMenus[Emul],EMclear);    /* BYU 2.4.14 */
  138.         DisableItem ( myMenus[Emul],EMscreensize);
  139.         DisableItem ( myMenus[Emul],EMsetup);
  140.         DisableItem ( myMenus[Emul],EMfont);
  141.         DisableItem ( myMenus[Emul],EMsize);
  142.         DisableItem ( myMenus[Emul],EMcolor);
  143.         DisableItem ( myMenus[Emul],EMcapture);    /* BYU 2.4.18 */
  144.  
  145.         DisableItem( myMenus[Net ],NEftp);
  146.         DisableItem( myMenus[Net ],NEip);
  147.         DisableItem( myMenus[Net ],NEayt);
  148.         DisableItem( myMenus[Net ],NEao);
  149.         DisableItem( myMenus[Net ],NEinter);
  150.         DisableItem( myMenus[Net ],NEec);
  151.         DisableItem( myMenus[Net ],NEel);
  152.         DisableItem( myMenus[Net ],NEscroll);
  153.  
  154.         if (TelInfo->ScrlLock) {
  155.             TelInfo->ScrlLock=0;
  156.             CheckItem(myMenus[Net ], NEscroll,FALSE);
  157.             }
  158.         }
  159.     else {
  160.         EnableItem ( myMenus[Fil],FLsave);
  161.  
  162. /*        EnableItem ( myMenus[Fil],FLprint); */
  163.  
  164.         EnableItem ( myMenus[Emul],EMbs);
  165.         EnableItem ( myMenus[Emul],EMdel);
  166.         EnableItem ( myMenus[Emul],EMecho);
  167.         EnableItem ( myMenus[Emul],EMwrap);
  168.         if (nNational > 0) {
  169.             EnableItem ( myMenus[National], 0);
  170.             }
  171.         EnableItem ( myMenus[Emul],EMscroll);
  172.         EnableItem ( myMenus[Emul],EMreset);
  173.         EnableItem ( myMenus[Emul],EMjump);
  174.         EnableItem ( myMenus[Emul],EMpage);
  175.         EnableItem ( myMenus[Emul],EMclear);    /* BYU 2.4.14 */
  176.         EnableItem ( myMenus[Emul],EMscreensize);
  177.         EnableItem ( myMenus[Emul],EMsetup);
  178.         EnableItem ( myMenus[Emul],EMfont);
  179.         EnableItem ( myMenus[Emul],EMsize);
  180.         EnableItem ( myMenus[Emul],EMcapture);    /* BYU 2.4.18 */
  181.     
  182.         if (theWorld.hasColorQD) 
  183.             EnableItem ( myMenus[Emul],EMcolor);
  184.  
  185.         EnableItem ( myMenus[Net ],NEftp);
  186.         EnableItem ( myMenus[Net ],NEip);
  187.         EnableItem ( myMenus[Net ],NEayt);
  188.         EnableItem ( myMenus[Net ],NEao);
  189.         EnableItem ( myMenus[Net ],NEinter);
  190.         EnableItem ( myMenus[Net ],NEec);
  191.         EnableItem ( myMenus[Net ],NEel);
  192.         EnableItem ( myMenus[Net ],NEscroll);
  193.     }
  194.  
  195. }
  196.  
  197. /*    switchMenus( which) - Switch from our current menus to the key menus (1)
  198.  *                          or the normal menus (0). */
  199. void switchMenus(short which)
  200. {
  201.     short i;
  202.  
  203.     DeleteMenu( fileMenu);                    /* Take them from the menu bar */
  204.     DeleteMenu( editMenu);
  205.     DeleteMenu( termMenu);
  206.     DeleteMenu(  netMenu);
  207. //    if (gApplicationPrefs->KeyPadAndFuncMenus) {    /* Baylor */
  208.         DeleteMenu(  keyMenu);                /* Baylor */
  209.         DeleteMenu( funcMenu);                /* Baylor */
  210. //        }                                    /* Baylor */
  211.     DeleteMenu(NfileMenu);                    /* Take them from the menu bar */
  212.     DeleteMenu(NeditMenu);
  213.     DeleteMenu(NtermMenu);
  214.     DeleteMenu(NnetMenu);
  215.  
  216.     if (which) {
  217.         myMenus[Fil ] = GetMenu(NfileMenu);
  218.         myMenus[Edit] = GetMenu(NeditMenu);
  219.         myMenus[Emul] = GetMenu(NtermMenu);
  220.         myMenus[Net ] = GetMenu(NnetMenu );
  221.         myMenus[Keypad] = GetMenu(keyMenu);            /* Baylor */
  222.         myMenus[Function] = GetMenu(funcMenu);        /* Baylor */
  223.  
  224.         DelMenuItem(myMenus[Conn],COnext);
  225.         InsMenuItem(myMenus[Conn],(StringPtr)"\017Next Session/N\0",0);
  226.         }
  227.     else {
  228.         myMenus[Fil ] = GetMenu(fileMenu);
  229.         myMenus[Edit] = GetMenu(editMenu);
  230.         myMenus[Emul] = GetMenu(termMenu);
  231.         myMenus[Net ] = GetMenu( netMenu);
  232.         myMenus[Keypad] = GetMenu(keyMenu);            /* Baylor */
  233.         myMenus[Function] = GetMenu(funcMenu);        /* Baylor */
  234.  
  235.         DelMenuItem(myMenus[Conn],COnext);
  236.         InsMenuItem(myMenus[Conn],(StringPtr)"\015Next Session\0",0);
  237.         }
  238.  
  239.     for(i=1; i<Conn; i++)
  240.         InsertMenu( myMenus[i], connMenu);    /* Put them in the menu bar */
  241.  
  242.     if (gApplicationPrefs->KeyPadAndFuncMenus) {            /* Baylor */
  243.         InsertMenu(myMenus[Keypad], 0);                        /* Baylor */
  244.         InsertMenu(myMenus[Function], 0);                    /* Baylor */
  245.         }
  246.  
  247.     AdjustMenus();            /* Hilite the right stuff */
  248.  
  249.     if (TelInfo->MacBinary)
  250.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  251.     else
  252.         CheckItem(myMenus[Fil],FLbin,FALSE);
  253.  
  254.     if (TelInfo->ftplogon)
  255.         CheckItem(myMenus[Fil],FLlog,TRUE);        /* and the log .... */
  256.     else
  257.         CheckItem(myMenus[Fil],FLlog,FALSE);
  258.  
  259.     if (TelInfo->ScrlLock)                                 /* and the Suspend network ... */
  260.         CheckItem(myMenus[Net], NEscroll,TRUE);
  261.     else 
  262.         CheckItem(myMenus[Net], NEscroll,FALSE);
  263.  
  264.     if (TelInfo->numwindows>0)                            /* and set the BSDEL flag */
  265.         CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,FALSE);
  266.  
  267.     DrawMenuBar();                                /* Draw what we have done */
  268.  
  269.     SetupOpSpecSubmenu(myMenus[OpSpec]);
  270.  
  271.     if (!theWorld.hasColorQD)
  272.         DisableItem( myMenus[Emul], EMcolor);
  273. }
  274.  
  275. /*    setupmenu - Set up (load) all menus and prepare menu bar.
  276.  *                set default check marks. */
  277. void setupmenu(short def)
  278. {
  279.     myMenus[0] = GetMenu(appleMenu);                /* Get all of our friendly menus */
  280.     myMenus[Conn] = GetMenu(connMenu);
  281.     myMenus[Font] = GetMenu(fontMenu);
  282.     myMenus[Sizem] = GetMenu(sizeMenu);
  283.     myMenus[OpSpec] = GetMenu(opspecMenu);
  284.     myMenus[PrefsSub] = GetMenu(prefsMenu);
  285.     myMenus[National] = GetMenu(transMenu);
  286.     myMenus[Keypad] = GetMenu(keyMenu);            /* Baylor */
  287.     myMenus[Function] = GetMenu(funcMenu);        /* Baylor */
  288.  
  289.     gApplicationPrefs->KeyPadAndFuncMenus = true;    /* Baylor - oh, what the heck. Just use'em. */
  290.  
  291.     AddResMenu(myMenus[0], 'DRVR');                    /* Add in the DA's */
  292.  
  293.     InsertMenu(myMenus[0], 0);                        /* Insert the Menus into the bar */
  294.     InsertMenu(myMenus[Conn], 0);
  295.     if (gApplicationPrefs->KeyPadAndFuncMenus) {    /* Baylor */
  296.         InsertMenu(myMenus[Keypad], 0);                /* Baylor */
  297.         InsertMenu(myMenus[Function], 0);            /* Baylor */
  298.         }
  299.     InsertMenu(myMenus[Font], -1);
  300.     InsertMenu(myMenus[Sizem], -1);
  301.     InsertMenu(myMenus[OpSpec], -1);
  302.     InsertMenu(myMenus[National], -1);
  303.     InsertMenu(myMenus[PrefsSub], -1);
  304.  
  305.     InsertResMenu(myMenus[Font], 'FONT', 0);    /* Put the fonts in the font menu, 
  306.                                                     before the 'Other' */
  307.     SetupOpSpecSubmenu(myMenus[OpSpec]);
  308.     switchMenus(def);
  309. }
  310.  
  311. void CheckOpSpecSubmenu(void)
  312. {
  313.     SetupOpSpecSubmenu(myMenus[OpSpec]);
  314. }
  315.  
  316. void SetupOpSpecSubmenu(MenuHandle theMenu)
  317. {
  318.     short            scratchshort;
  319.         
  320.     scratchshort = CountMItems(theMenu);
  321.     for (; scratchshort>0; scratchshort--) DelMenuItem(theMenu, scratchshort);
  322.  
  323.     UseResFile(TelInfo->SettingsFile);
  324.     AddResMenu(theMenu, SESSIONPREFS_RESTYPE);
  325. }
  326.  
  327. /*    updateMenuChecks() - update the check marks for file transfer
  328.  *                         (MacBinary) */
  329.  
  330. void updateMenuChecks( void)
  331. {
  332.     if (TelInfo->MacBinary)
  333.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  334.     else
  335.         CheckItem(myMenus[Fil],FLbin,FALSE);
  336. }
  337.  
  338. /*    DisplayMacBinary()    - Sets the macbinary check mark according to the MacBinary flag */
  339. void DisplayMacBinary( void)
  340. {
  341.     if (TelInfo->MacBinary)
  342.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  343.     else
  344.         CheckItem(myMenus[Fil],FLbin,FALSE);
  345. }
  346.  
  347. /*CheckFonts()        - Place checkmarks and outlines on the appropriate
  348.  *                          menu items for the fonts */
  349. void CheckFonts(void)
  350. {
  351.     short     i, fsiz, fnum;
  352.     long    itemFontSize;
  353.     Str255     temp, itemString;
  354.  
  355.     RSgetfont( screens[scrn].vs, &fnum, &fsiz);
  356.     GetFontName(fnum, temp);
  357.     
  358.     for(i=1; i<= CountMItems( myMenus[Font]); i++)
  359.         {
  360.         GetItem( myMenus[Font], i, itemString);
  361.         if (EqualString(temp, itemString, FALSE, FALSE))
  362.             CheckItem( myMenus[Font], i, TRUE);            /* Check the current font */
  363.         else
  364.             CheckItem( myMenus[Font], i, FALSE);
  365.         }
  366.     
  367.     for(i=1; i<=CountMItems( myMenus[Sizem]); i++) {
  368.         GetItem( myMenus[Sizem], i, itemString);            /* JMB 2.6 -- Much safer to do it */
  369.         StringToNum(itemString, &itemFontSize);            /*                this way! */
  370.  
  371.         if (fsiz == (short)itemFontSize)
  372.             CheckItem( myMenus[Sizem], i, TRUE);            /* Check Our Current Size */
  373.         else
  374.             CheckItem( myMenus[Sizem], i, FALSE);
  375.  
  376.         if (RealFont( fnum, (short)itemFontSize))        /* Outline All Available REAL Sizes */
  377.             SetItemStyle( myMenus[Sizem], i, outline);
  378.         else
  379.             SetItemStyle( myMenus[Sizem], i, 0);
  380.         }
  381. }
  382.  
  383. /*    applAbout - display the about dialog for the application.*/
  384. void applAbout( void)
  385. {
  386.     DialogPtr About;
  387.     short itemhit;
  388.  
  389.     About=GetNewMyDialog( AboutDLOG, (Ptr) 0L,(WindowPtr) -1L, (void *)ThirdCenterDialog);
  390.     if (About) {
  391.         UItemAssign( About, 2, VersionNumberUPP);
  392.         ModalDialog(NULL, &itemhit);
  393.         DisposDialog(About);
  394.         }
  395. }
  396.  
  397. short ReallyClose( short scrn)
  398. {
  399.     DialogPtr    dtemp;
  400.     short        item;
  401.     Str255        scratchPstring;
  402.     
  403.     SetCursor(theCursors[normcurs]);
  404.  
  405.     GetWTitle(screens[scrn].wind, scratchPstring);
  406.     ParamText(scratchPstring, NULL, NULL, NULL);
  407.     
  408.     dtemp = GetNewMyDialog( CloseDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  409.  
  410.     item = DLOGCancel +1;
  411.     while (item> DLOGCancel)
  412.         ModalDialog(DLOGwOK_CancelUPP, &item);
  413.  
  414.     DisposDialog( dtemp);
  415.  
  416.     updateCursor(1);
  417.     
  418.     if (item == DLOGCancel) return(0);
  419.  
  420.     return(1);
  421. }
  422.  
  423. PicHandle RGtoPICT(short i)
  424. {
  425.     short j;
  426.     PicHandle tpic;
  427.     Rect trect;
  428.  
  429.     SetRect(&trect,0,0,384,384);
  430.     j=VGnewwin(TEK_DEVICE_PICTURE,VGgetVS(i));            /* NCSA 2.5: get the right VS */
  431.     RGMPsize( &trect );
  432.     VGzcpy( i, j);                /* Love dat zm factr */
  433.     tpic=OpenPicture(&trect);
  434.     ClipRect(&trect);
  435.     
  436.     VGredraw(i,j);
  437.     ClosePicture();
  438.     VGclose(j);
  439.  
  440.     return(tpic);
  441. }
  442.  
  443. /* 
  444.  * copyGraph    - Copy the current graphics screen.
  445.  *            dnum - the number of the drawing to copy .
  446.  */
  447. void copyGraph( short dnum)
  448. {
  449.     long tlong;                    /* Temporary Variable */
  450.     PicHandle tpic;                /* Mental picture of the thing */
  451.  
  452.     tpic=RGtoPICT(dnum);            /* Get the picture */
  453.     tlong=ZeroScrap();                /* Nobody else can live here */
  454.     HLock((Handle) tpic);                    /* Lock it for Puting */
  455.     tlong=PutScrap(GetHandleSize((Handle) tpic),'PICT', (Ptr) *tpic);    /* Store as a PICT */
  456.     HUnlock((Handle) tpic);                    /* Unlock so we can toss it */
  457.     KillPicture(tpic);                /* Kill the picture..... */
  458. }                
  459.  
  460. /* 
  461.  * copyText    - Copy the current selection on the virtual screen
  462.  *            vs - the number of the virtual screen to copy from
  463.  */
  464.  
  465. void copyText( short vs)
  466. {
  467.     char **charh;            /* where to store the characters */
  468.     long tlong;                /* Necessary temporary variable */
  469.  
  470.     tlong=ZeroScrap();        /* This Scrap aint big enough for the both of us */
  471.  
  472.     charh=RSGetTextSel(vs,0);        /* Get the text selection */
  473.  
  474.     if (charh == (char **)-1L)
  475.         OutOfMemory(400);
  476.     else if (charh != (char **)0L) {    /* BYU LSC - Can't do anything without characters */
  477.         HLock(charh);                /* Lock for putting */
  478.         tlong=PutScrap(GetHandleSize(charh),'TEXT',*charh);
  479.                                     /* Put it as a TEXT resource */
  480.         HUnlock(charh);                /* Unlock for disposal */
  481.         DisposHandle(charh);        /* Kill the chars */
  482.         }
  483. }
  484.  
  485. /* 
  486.  * copyTable   - Copy the current selection on the virtual screen
  487.  *            vs - the number of the virtual screen to copy from
  488.  */
  489.  
  490. void copyTable( short vs)
  491. {
  492.     char **charh;            /* where to store the characters */
  493.     long tlong;                /* Necessary temporary variable */
  494.  
  495.     tlong=ZeroScrap();        /* This Scrap aint big enough for the both of us */
  496.  
  497.     charh=RSGetTextSel(vs, gApplicationPrefs->CopyTableThresh);        /* Get the text selection */
  498.  
  499.     if (charh>(char **)0L) {                    /* BYU LSC - Can't do anything without characters */
  500.         HLock(charh);                /* Lock for putting */
  501.         tlong=PutScrap(GetHandleSize(charh),'TEXT',*charh);
  502.                                     /* Put it as a TEXT resource */
  503.         HUnlock(charh);                /* Unlock for disposal */
  504.         DisposHandle(charh);        /* Kill the chars */
  505.         }
  506.     else putln("No characters to copy darn it!");
  507. }
  508.  
  509. /*
  510.  *    paste - Paste the resource from the scrap into the current WIND, if
  511.  *            and only if it is really text
  512.  */
  513.  
  514. void paste( void)
  515. {
  516.     long
  517.         off,                /* offset */
  518.         length;                /* the lenght of what is on the Scrap */
  519.  
  520.     if (screens[scrn].clientflags & PASTE_IN_PROGRESS) {  // One paste at a time, please
  521.         SysBeep(4);
  522.         return;
  523.         }
  524.         
  525.     /* Flush the buffer if we have echo */
  526.     if (screens[scrn].echo &&                 /* BYU */
  527.         screens[scrn].kblen>0) {            /* BYU */
  528.         netwrite( screens[scrn].port, screens[scrn].kbbuf,
  529.                     screens[scrn].kblen);    /* if full send buffer */
  530.         screens[scrn].kblen=0;
  531.         }
  532.  
  533.     if (GetScrap(0L, 'TEXT', &off)<=0L)        /* If there are no TEXT res's */
  534.             return;                        /* then we can't paste it */
  535.  
  536.     screens[scrn].outhand=NewHandle(0L);    /* create a handle to put chars in */
  537.  
  538.     length= GetScrap( screens[scrn].outhand, 'TEXT',&off);
  539.                                             /* Store the scrap into the handle */
  540.     screens[scrn].outlen = length;            /* Set the length */
  541.     HLock(screens[scrn].outhand);            /* Lock the Handle down for safety */
  542.     screens[scrn].outptr=*screens[scrn].outhand;    /* Set the pointer */
  543.  
  544.     screens[scrn].clientflags |= PASTE_IN_PROGRESS;
  545.     screens[scrn].incount = 0;
  546.     screens[scrn].outcount = 0;
  547.     
  548.     trbuf_mac_nat((unsigned char *)screens[scrn].outptr,screens[scrn].outlen, screens[scrn].national);    /* LU: translate to national chars */
  549.  
  550.     pasteText( scrn);    /* BYU LSC - routine to paste to net, w/echo if neccessary */
  551. }
  552.  
  553. void displayStatus(short n)
  554. {
  555.     DialogPtr        dptr;
  556.     short            item;
  557.     Str255            scratchPstring;
  558.     
  559.     SetCursor(theCursors[normcurs]);
  560.     
  561.     switch(screens[n].active) {
  562.         case CNXN_ISCORPSE:
  563.             GetWTitle(screens[n].wind, scratchPstring);
  564.             ParamText( scratchPstring, "\pawaiting dismissal", NULL, NULL);
  565.             break;
  566.         case CNXN_OPENING:
  567.             ParamText( screens[n].machine,"\pbeing opened", NULL, NULL);
  568.             break;
  569.         default:
  570.             ParamText( screens[n].machine,"\pbeing looked up", NULL, NULL);
  571.         }
  572.  
  573.     dptr = GetNewMyDialog( StatusDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  574.  
  575.     item = DLOGCancel+1;
  576.     while (item > DLOGCancel)
  577.         ModalDialog(DLOGwOK_CancelUPP, &item);
  578.  
  579.     updateCursor(1);
  580.     
  581.     if (item == DLOGCancel) {
  582.         netclose(screens[n].port);
  583.         destroyport( n);
  584.         }    
  585.  
  586.     DisposDialog(dptr);
  587. }
  588.  
  589. /*
  590.  *    changeport - handle the menu updates for changing from one port to another
  591.  */
  592. void changeport(short oldprt, short newprt)
  593. {
  594.  
  595.     //sprintf(tempspot,"oldscrn: %d, newscrn: %d",oldprt,newprt); putln(tempspot);
  596.     
  597.     if (screens[oldprt].active == CNXN_ACTIVE) 
  598.         CheckItem(myMenus[Conn], oldprt + FIRST_CNXN_ITEM, FALSE);        /* Adjust Conn menu */
  599.     CheckItem(myMenus[Conn], newprt + FIRST_CNXN_ITEM, TRUE);
  600.  
  601.     CheckItem(myMenus[Emul], EMbs,FALSE);                        /* Adjust BS */
  602.     CheckItem(myMenus[Emul], EMdel,FALSE);
  603.     CheckItem(myMenus[Emul], EMbs+screens[newprt].bsdel,TRUE);    /* and DEL */
  604.  
  605.     if (screens[newprt].tektype < 0) {    // TEK is inhibited
  606.         DisableItem(myMenus[Emul],EMclear);
  607.         DisableItem(myMenus[Emul],EMpage);
  608.         }
  609.     else {
  610.         EnableItem(myMenus[Emul],EMclear);
  611.         EnableItem(myMenus[Emul],EMpage);
  612.     
  613.         if (screens[newprt].tekclear)                /* BYU 2.4.8 */
  614.             CheckItem(myMenus[Emul],EMclear,TRUE);    /* BYU 2.4.8 */
  615.         else                                         /* BYU 2.4.8 */
  616.             CheckItem(myMenus[Emul],EMclear,FALSE);    /* BYU 2.4.8 */
  617.         }
  618.         
  619.     if (screens[newprt].ESscroll)
  620.         CheckItem(myMenus[Emul],EMscroll,TRUE);
  621.     else 
  622.         CheckItem(myMenus[Emul],EMscroll,FALSE);
  623.  
  624.     if (screens[newprt].echo)                     /* LOCAL ECHO */
  625.         CheckItem(myMenus[Emul],EMecho,TRUE);
  626.     else                                         /* REMOTE ECHO */
  627.         CheckItem(myMenus[Emul],EMecho,FALSE);
  628.         
  629.     if (screens[newprt].wrap)                     /* wrap on */
  630.         CheckItem(myMenus[Emul],EMwrap,TRUE);
  631.     else                                         /* wrap off */
  632.         CheckItem(myMenus[Emul],EMwrap,FALSE);
  633.  
  634.     if (VSiscapturing(screens[newprt].vs))                /* BYU 2.4.18 */
  635.         CheckItem(myMenus[Emul], EMcapture,TRUE);        /* BYU 2.4.18 */
  636.     else                                                /* BYU 2.4.18 */
  637.         CheckItem(myMenus[Emul], EMcapture,FALSE);        /* BYU 2.4.18 */
  638.  
  639.     if (screens[newprt].arrowmap)                        /* JMB */
  640.         CheckItem(myMenus[Emul],EMarrowmap, TRUE);        /* JMB */
  641.     else                                                /* JMB */
  642.         CheckItem(myMenus[Emul],EMarrowmap, FALSE);        /* JMB */
  643.         
  644.     if (screens[newprt].pgupdwn)                        /* JMB */
  645.         CheckItem(myMenus[Emul],EMpgupdwn, TRUE);        /* JMB */
  646.     else                                                /* JMB */
  647.         CheckItem(myMenus[Emul],EMpgupdwn, FALSE);        /* JMB */
  648.     
  649.     scrn=newprt;
  650.  
  651.     CheckFonts();
  652.  
  653.     CheckNational(screens[newprt].national);
  654. }
  655.  
  656. // Returns TRUE if the user cancelled the quit
  657. Boolean    HandleQuit(void)
  658. {
  659.     short    i;
  660.     
  661.     if (TelInfo->numwindows>0) {
  662.         if (AskUserAlert(REALLY_QUIT_QUESTION, FALSE)) {
  663.             for (i = TelInfo->numwindows - 1; i >= 0; i--) {
  664.                 netclose(screens[i].port);
  665.                 destroyport(i);
  666.                 }
  667.             }
  668.         else
  669.             return (TRUE);
  670.       }
  671.       
  672.     quit();
  673.     return (FALSE);
  674. }
  675.  
  676. /*
  677.  *    HandleMenuCommand - preform a command denoted by the arguments.
  678.  *        mResult - the result of the menu event
  679.  *        modifiers- modifiers from the menu event
  680.  */
  681.  
  682. void HandleMenuCommand( long mResult, short modifiers)
  683. {
  684.     register short i;
  685.     short theItem, theMenu;
  686.  
  687.     theMenu = mResult >> 16;
  688.     theItem = mResult & 0xffff;
  689.     switch(theMenu) {
  690.     case appleMenu:
  691.         if (theItem==1)                /* About Dialog */
  692.             applAbout();
  693.         else
  694.           {
  695.             Str255
  696.                 name;
  697.             GetItem(myMenus[0], theItem, name);        /* Desk accessory */
  698.             OpenDeskAcc(name);
  699.           }
  700.         break;
  701.  
  702.     case fileMenu:
  703.     case NfileMenu:
  704.         switch(theItem) {            
  705.             
  706.         case FLopen:
  707.             PresentOpenConnectionDialog();                    /* Open a connection */                
  708.             break;
  709.  
  710.         case FLclose:                                    /* Close a connection */
  711.             CloseAWindow(FrontWindow());
  712.             break;
  713.  
  714.         case FLload:                                /* Load a set */
  715.             LoadSet();
  716.             break;
  717.         case FLsave:                                /* Save a set */
  718.             if (TelInfo->numwindows<1) break;
  719.             SaveSet();
  720.             break;
  721.         case FLbin:                                    /* Toggle MacBinary on/off */
  722.             TelInfo->MacBinary = !TelInfo->MacBinary;
  723.             if (TelInfo->MacBinary) {
  724.                 CheckItem(myMenus[Fil], FLbin,TRUE);
  725.                 }
  726.             else {
  727.                 CheckItem(myMenus[Fil], FLbin,FALSE);
  728.                 }
  729.             break;
  730.  
  731.         case FLlog:                                        /* Toggle FTP window on/off*/
  732.             TelInfo->ftplogon=!TelInfo->ftplogon;
  733.             if(TelInfo->ftplogon) {
  734.                 CheckItem(myMenus[Fil],FLlog,TRUE);
  735.                 RSshow(ftplog->vs);
  736.                 SelectWindow(ftplog->wind);
  737.                 }
  738.             else {
  739.                 CheckItem(myMenus[Fil],FLlog,FALSE);
  740.                 RShide(ftplog->vs);
  741.                 }
  742.             break;
  743.  
  744.         case FLprint:                                /* Print Selection (or gr) */
  745.             PrintSelection();
  746.             break;
  747.  
  748.         case FLpset:                                    /* Set up for printer */
  749.             PrintPageSetup();
  750.             break;
  751.  
  752.         case FLquit:
  753.             (void) HandleQuit();
  754.             break;
  755.  
  756.         }
  757.         break;
  758.  
  759.     case editMenu:
  760.     case NeditMenu:
  761.         if (!SystemEdit(theItem-1)) {                /* Is this mine? */
  762.             switch(theItem) {
  763.             case EDcopy:                            /* Copy */
  764.                 i = MacRGfindwind(FrontWindow());    /* is ICR window? */
  765.                 if (i >= 0)
  766.                     MacRGcopy(FrontWindow());        /* copy the ICR window */
  767.                 else {
  768.                     i=RGgetdnum(FrontWindow());
  769.                     if (i>-1)                        /* Copy Graphics */
  770.                         copyGraph( i);
  771.                     else                            /* Copy Text */
  772.                         if ( (i=RSfindvwind(FrontWindow())) >-1)
  773.                             copyText( i);
  774.                 }
  775.                 break;
  776.  
  777.             case EDcopyt:                            /* Copy Table */
  778.                 /* 
  779.                 *  tech note #180 trick to get MultiFinder to pay attention 
  780.                 */
  781.                 if (!SystemEdit(EDcopy-1)) {        /* tell it we did a copy */
  782.                     i=RGgetdnum(FrontWindow());
  783.                     if (i>-1)            /* Copy Graphics */
  784.                         copyGraph( i);
  785.                     else                /* Copy Text */
  786.                         if ( (i=RSfindvwind(FrontWindow())) >-1)
  787.                             copyTable( i);
  788.                 }
  789.                 break;
  790.  
  791.             case EDpaste:                            /* Paste */
  792.                 if (TelInfo->numwindows<1)
  793.                         break;
  794.                     else paste();            /* Paste if there is a wind to do to*/
  795.                 break;
  796.             case EDmacros:                            /* Set them Macros */
  797.                 Macros();
  798.                 break;
  799.             default:
  800.                 break;
  801.             }
  802.         }
  803.         break;
  804.  
  805.     case connMenu:
  806.     case NconnMenu:
  807.         if (theItem == COnext) {
  808.             short    scratchshort;
  809.             if (TelInfo->numwindows >1) {
  810.                 scratchshort = WindowPtr2ScreenIndex(FrontWindow()) + 1;
  811.                 // Skip over inactive connections
  812.                 while(    (screens[scratchshort].active != CNXN_ACTIVE) &&
  813.                         (screens[scratchshort].active != CNXN_ISCORPSE) &&
  814.                         (scratchshort <= TelInfo->numwindows+1))                        
  815.                     scratchshort++;
  816.                     
  817.                 if ((scratchshort < 0) || (scratchshort >= TelInfo->numwindows))
  818.                     scratchshort = 0;
  819.                 SelectWindow(screens[scratchshort].wind);
  820.                 }
  821.             break;
  822.             }
  823.         
  824.         if (theItem == COtitle)    {
  825.             ChangeWindowName(FrontWindow());
  826.             break;
  827.             }
  828.             
  829.         if (theItem >= FIRST_CNXN_ITEM) {
  830.             if ((theItem - FIRST_CNXN_ITEM-1)>(TelInfo->numwindows+1)) break;  /* rotten danish */
  831.             if (screens[theItem - FIRST_CNXN_ITEM].active != CNXN_ACTIVE) {
  832.                 displayStatus(theItem - FIRST_CNXN_ITEM);    /* Tell them about it..... */
  833.                 break;
  834.                 }
  835.             else {
  836.                 HiliteWindow(screens[scrn].wind, FALSE);
  837.                 changeport(scrn,(theItem - FIRST_CNXN_ITEM));
  838.                 if (!(modifiers &  optionKey)) SelectWindow(screens[scrn].wind);
  839.                 else HiliteWindow(screens[scrn].wind, TRUE);
  840.                 }
  841.             }
  842.         break;
  843.  
  844.     case netMenu:
  845.     case NnetMenu:
  846.         switch(theItem) {
  847.         case NEftp:                                        /* Send FTP command */
  848.         case NEip:                                        /* Send IP Number */
  849.             if (TelInfo->numwindows<1) break;
  850.             {    char tmpout[30];                        /* Basically the same except for */
  851.                 unsigned char tmp[4];                    /* The ftp -n phrase in NEftp */
  852.  
  853.                 if (screens[scrn].echo && (screens[scrn].kblen>0)) {
  854.                     netwrite( screens[scrn].port, screens[scrn].kbbuf,
  855.                                 screens[scrn].kblen);/* if not empty send buffer */
  856.                     screens[scrn].kblen=0;
  857.                     }
  858.                 netgetip(tmp);
  859.                 if (theItem == NEftp) {
  860.                     if ((gFTPServerPrefs->ServerState == 1) && !(modifiers & shiftKey))
  861.                         sprintf(tmpout,"ftp -n %d.%d.%d.%d\015\012",tmp[0],tmp[1],tmp[2],tmp[3]);
  862.                     else
  863.                         sprintf(tmpout,"ftp %d.%d.%d.%d\015\012",tmp[0],tmp[1],tmp[2],tmp[3]);
  864.                     }
  865.                 else
  866.                     sprintf(tmpout,"%d.%d.%d.%d",tmp[0],tmp[1],tmp[2],tmp[3]);
  867.                 netwrite(screens[scrn].port,tmpout,strlen(tmpout));
  868.                 if (screens[scrn].echo)
  869.                     VSwrite(screens[scrn].vs,tmpout, strlen(tmpout));
  870.             }
  871.             break;
  872.  
  873.         case NEayt:                                /* Send "Are You There?"*/
  874.             if (TelInfo->numwindows<1) break;
  875.             netpush(screens[scrn].port);
  876.             netwrite(screens[scrn].port, "\377\366",2);
  877.             break;
  878.  
  879.         case NEao:                                /* Send "Abort Output"*/
  880.             if (TelInfo->numwindows<1) break;
  881.             netpush(screens[scrn].port);
  882.             netwrite(screens[scrn].port, "\377\365",2);
  883.             screens[ scrn].timing = 1;                        /* set emulate to TMwait */
  884.             netwrite(screens[scrn].port, "\377\375\006",3);        /* send TM */
  885.             break;
  886.  
  887.         case NEinter:                                /* Send "Interrupt Process"*/
  888.             if (TelInfo->numwindows<1) break;
  889.             netpush(screens[scrn].port);
  890.             netwrite(screens[scrn].port, "\377\364",2);
  891.             screens[ scrn].timing = 1;                        /* set emulate to TMwait */
  892.             netwrite(screens[scrn].port, "\377\375\006",3);        /* send TM */
  893.             break;
  894.  
  895.         case NEec:                                /* Send "Erase Character"*/
  896.             if (TelInfo->numwindows<1) break;
  897.             netpush(screens[scrn].port);
  898.             netwrite(screens[scrn].port, "\377\367",2);
  899.             break;
  900.  
  901.         case NEel:                                /* Send "Erase Line"*/
  902.             if (TelInfo->numwindows<1) break;
  903.             netpush(screens[scrn].port);
  904.             netwrite(screens[scrn].port, "\377\370",2);
  905.             break;
  906.             
  907.         case NEscroll:                            /* Suspend Network */
  908.             TelInfo->ScrlLock=!TelInfo->ScrlLock;
  909.             if (TelInfo->ScrlLock) 
  910.                 CheckItem(myMenus[Net], NEscroll,TRUE);
  911.             else 
  912.                 CheckItem(myMenus[Net], NEscroll,FALSE);
  913.             break;
  914.  
  915.         case NEnet:                                /* Show Network Numbers */
  916.             showNetNumbers();
  917.             break;
  918.  
  919.         default:
  920.             break;
  921.         }
  922.         break;
  923.  
  924.     case termMenu:
  925.     case NtermMenu:
  926.         switch(theItem) {
  927.  
  928.         case EMbs:                                /* Backspace for backspace  */
  929.             if (TelInfo->numwindows<1) break;
  930.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,FALSE);
  931.             screens[scrn].bsdel=0;
  932.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,TRUE);
  933.             break;
  934.         
  935.         case EMdel:                                /* Delete for backspace */
  936.             if (TelInfo->numwindows<1) break;
  937.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,FALSE);
  938.             screens[scrn].bsdel=1;
  939.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,TRUE);
  940.             break;
  941.  
  942.         case EMecho:                                /* Toggle Local Echo (if poss.) */
  943.             if (TelInfo->numwindows < 1) break;
  944.             if (screens[scrn].echo && (screens[scrn].kblen>0)) {
  945.                 netwrite( screens[scrn].port, screens[scrn].kbbuf,
  946.                             screens[scrn].kblen);    /* if not empty send buffer */
  947.                 screens[scrn].kblen=0;
  948.                 }
  949.             screens[scrn].echo= !screens[scrn].echo;    /* toggle */
  950.             if (screens[scrn].echo) {                    /* LOCAL ECHO */
  951.                 netwrite(screens[scrn].port,"\377\376\001",3);
  952.                 CheckItem(myMenus[Emul],EMecho,TRUE);
  953.                 }
  954.             else {                                        /* REMOTE ECHO */
  955.                 netwrite(screens[scrn].port,"\377\375\001",3);
  956.                 CheckItem(myMenus[Emul],EMecho,FALSE);
  957.                 }
  958.             break;
  959.             
  960.         case EMwrap:                                /* wrap mode */
  961.             if (TelInfo->numwindows < 1) break;
  962.             if (!screens[scrn].wrap) {                /* is off, turn on */
  963.                 screens[scrn].wrap = 1;
  964.                 CheckItem( myMenus[Emul],EMwrap, TRUE);
  965.                 VSwrite(screens[scrn].vs, "\033[?7h",5);    /* kick emulator */
  966.                 }
  967.             else {
  968.                 screens[scrn].wrap = 0;
  969.                 CheckItem( myMenus[Emul],EMwrap, FALSE);
  970.                 VSwrite(screens[scrn].vs, "\033[?7l",5);
  971.                 }
  972.             break;
  973.         
  974.         case EMarrowmap:                                        /* JMB */
  975.             if (TelInfo->numwindows < 1) break;                    /* JMB */
  976.             screens[scrn].arrowmap = !screens[scrn].arrowmap;    /* JMB */
  977.             if (screens[scrn].arrowmap)                            /* JMB */
  978.                 CheckItem( myMenus[Emul], EMarrowmap, TRUE);    /* JMB */
  979.             else                                                /* JMB */
  980.                 CheckItem( myMenus[Emul], EMarrowmap, FALSE);    /* JMB */
  981.             break;                                                /* JMB */
  982.             
  983.         case EMpgupdwn:
  984.             if (TelInfo->numwindows < 1) break;                    /* JMB */
  985.             screens[scrn].pgupdwn = !screens[scrn].pgupdwn;        /* JMB */
  986.             if (screens[scrn].pgupdwn)                            /* JMB */
  987.                 CheckItem( myMenus[Emul], EMpgupdwn, TRUE);        /* JMB */
  988.             else                                                /* JMB */
  989.                 CheckItem( myMenus[Emul], EMpgupdwn, FALSE);    /* JMB */
  990.             break;                                                /* JMB */
  991.             
  992.         case EMscroll:                                        /* Scrollback on CLS */
  993.             if (TelInfo->numwindows<1) break;
  994.             screens[scrn].ESscroll = !screens[scrn].ESscroll;
  995.             VSscrolcontrol( screens[scrn].vs, -1, screens[scrn].ESscroll);
  996.             if (screens[scrn].ESscroll)
  997.                 CheckItem(myMenus[Emul],EMscroll, TRUE);
  998.             else
  999.                 CheckItem(myMenus[Emul],EMscroll, FALSE);
  1000.             break;
  1001.             
  1002.         case EMpage:                                    /* TEK page command */
  1003.             if (TelInfo->numwindows<1) break;
  1004.             parse( &screens[scrn],  (unsigned char *) "\033\014",2);    /* BYU LSC */
  1005.             break;
  1006.  
  1007.         case EMclear:                                /* BYU 2.4.8 - Clear on TEK page */
  1008.             if (TelInfo->numwindows<1) break;
  1009.             screens[scrn].tekclear = !screens[scrn].tekclear;
  1010.             if (screens[scrn].tekclear)
  1011.                 CheckItem(myMenus[Emul],EMclear, TRUE);
  1012.             else
  1013.                 CheckItem(myMenus[Emul],EMclear, FALSE);
  1014.             break;
  1015.  
  1016.         case EMscreensize:
  1017.             if (TelInfo->numwindows<1) break;        /* NCSA: SB */
  1018.             SetScreenDimensions((short)scrn);        /* NCSA: SB */
  1019.             break;
  1020.  
  1021.         case EMreset:                                    /* Reset Screen */
  1022.             if (TelInfo->numwindows<1) break;
  1023.             VSreset(screens[scrn].vs);                    /* Reset it */
  1024.             screens[scrn].timing=0;
  1025.             screens[scrn].wrap = 0;                        /* turns wrap off */
  1026.             CheckItem( myMenus[Emul],EMwrap, FALSE);
  1027.             break;
  1028.         case EMjump:                                    /* Jump Scroll */
  1029.             if (TelInfo->numwindows<1) break;
  1030.             FlushNetwork(scrn);                            /* Flush it */
  1031.             break;
  1032.             
  1033.         case EMsetup:                            /* need dialog to enter new key values */
  1034.             setupkeys();
  1035.             break;
  1036.  
  1037.         case EMcolor:                                        /* Set color */
  1038.             if (TelInfo->numwindows<1) break;
  1039.             if (theWorld.hasColorQD)
  1040.                 RScprompt(screens[scrn].vs);    /* Color it */
  1041.             break;
  1042.  
  1043.         case EMcapture:                                            /* BYU 2.4.18 - Capture session to file */
  1044.             if (VSiscapturing(screens[scrn].vs)) {                /* BYU 2.4.18 */
  1045.                 CloseCaptureFile(screens[scrn].vs);                /* BYU 2.4.18 */
  1046.             } else {                                            /* BYU 2.4.18 */
  1047.                 if(VSopencapture(scrn, screens[scrn].vs))        /* BYU 2.4.18 */
  1048.                     CheckItem(myMenus[Emul], EMcapture,TRUE);    /* BYU 2.4.18 */
  1049.             }                                                    /* BYU 2.4.18 */
  1050.  
  1051.             break;                                                /* BYU 2.4.18 */
  1052.  
  1053.         default:
  1054.             break;
  1055.         }
  1056.         break;
  1057.     case fontMenu:
  1058.         if (TelInfo->numwindows>0) {
  1059.             short     itemFontNum;
  1060.             Str255     temp;
  1061.             
  1062.             GetItem( myMenus[Font], theItem, temp);
  1063.             GetFNum( temp, &itemFontNum);
  1064.             
  1065.             RSchangefont( screens[scrn].vs, itemFontNum, 0);
  1066.             CheckFonts();
  1067.             }
  1068.         break;
  1069.     case sizeMenu:
  1070.         if (TelInfo->numwindows>0) 
  1071.         {
  1072.             long    itemFontSize;
  1073.             short     currentSize, junk;
  1074.             Str255     temp;
  1075.             short     numOfItems;
  1076.             
  1077.             numOfItems = CountMItems(myMenus[Sizem]);
  1078.             if (numOfItems == theItem) //use picked 'other...'
  1079.             {
  1080.                 RSgetfont(screens[scrn].vs, &junk, ¤tSize);    
  1081.                 itemFontSize = SetOtherFontSize(currentSize);
  1082.             }
  1083.             else
  1084.             {
  1085.                 GetItem( myMenus[Sizem], theItem, temp);    /* JMB 2.6 -- Much safer to do it */
  1086.                 StringToNum(temp, &itemFontSize);        /*                this way! */
  1087.             }
  1088.  
  1089.             RSchangefont( screens[scrn].vs, -1, itemFontSize);
  1090.             CheckFonts();
  1091.         }
  1092.         break;
  1093.     case opspecMenu:                                            // JMB
  1094.         OpenPortSpecial(myMenus[OpSpec], theItem);                // JMB
  1095.         break;                                                    // JMB
  1096.     case prefsMenu:
  1097.         switch(theItem) {
  1098.             case prfGlobal:
  1099.                 Cenviron();
  1100.                 break;
  1101.             case prfFTP:
  1102.                 Cftp();
  1103.                 break;
  1104.             case prfSess:
  1105.                 EditConfigType(SESSIONPREFS_RESTYPE, &EditSession);
  1106.                 CheckOpSpecSubmenu();
  1107.                 break;
  1108.             case prfTerm:
  1109.                 EditConfigType(TERMINALPREFS_RESTYPE, &EditTerminal);
  1110.                 break;
  1111.             case prfFTPUser:
  1112.                 EditConfigType(FTPUSER, &EditFTPUser);
  1113.             }
  1114.         break;
  1115.     case transMenu:
  1116.         if (TelInfo->numwindows>0) {
  1117.             CheckNational(theItem-1);        // Set up the menu
  1118.             transBuffer(screens[scrn].national, theItem-1);    // Translate the scrollback buffer
  1119.             // and redraw the screen
  1120.             VSredraw(screens[scrn].vs,0,0,VSmaxwidth(screens[scrn].vs),VSgetlines(screens[scrn].vs)-1);    /* LU */
  1121.             screens[scrn].national = theItem-1;
  1122.             }
  1123.         break;
  1124.     case keyMenu:
  1125.         KeyMenu(theItem);
  1126.         break;
  1127.     case funcMenu:
  1128.         FuncMenu(theItem);
  1129.         break;
  1130.     default:
  1131.         break;
  1132.     
  1133.     }
  1134.     HiliteMenu(0);
  1135.   } /* HandleMenuCommand */
  1136.  
  1137. //    Take the user's new translation choice and make sure the proper tables exist to do 
  1138. //        the translations.  If there is a problem, return the default translation as the chouce.
  1139. void    CheckNational(short choice)
  1140. {
  1141.     short i;
  1142.             
  1143.     for(i=1; i<=(nNational+1);i++)
  1144.         if ((choice+1) == i)                    /* Check the Current NatLang */
  1145.             CheckItem( myMenus[National], i, TRUE);
  1146.         else
  1147.             CheckItem( myMenus[National], i, FALSE);
  1148.  
  1149. }
  1150.  
  1151. /*
  1152.  *    extractmenu - remove a connection from the menu.
  1153.  */
  1154.  
  1155. void extractmenu(short screen)
  1156. {
  1157.     DelMenuItem(myMenus[Conn], screen + FIRST_CNXN_ITEM);
  1158.     AdjustMenus();
  1159. }
  1160.  
  1161. /*
  1162.  *    addinmenu - add a connection's name to the menu in position pnum. (name is
  1163.  *        an str255 pointed at by temps).
  1164.  */
  1165.  
  1166. void addinmenu( short screen, Str255 temps, char mark)
  1167. {
  1168.     InsMenuItem(myMenus[Conn], "\pDoh", (screen-1) + FIRST_CNXN_ITEM);
  1169.     SetItem(myMenus[Conn], screen + FIRST_CNXN_ITEM, temps);        // Avoid metas
  1170.     SetItemMark( myMenus[Conn], screen + FIRST_CNXN_ITEM, mark);
  1171.     AdjustMenus();
  1172. }
  1173.  
  1174. /*    Set the item mark for <scrn> to opening connection */
  1175. void SetMenuMarkToOpeningForAGivenScreen( short scrn)
  1176. {
  1177.     unsigned char c=0xa5;
  1178.  
  1179.     SetItemMark( myMenus[Conn], scrn + FIRST_CNXN_ITEM, c );
  1180. }
  1181.  
  1182. /*    Set the item mark for <scrn> to opened connection */
  1183. void SetMenuMarkToLiveForAGivenScreen( short scrn)
  1184. {
  1185.     SetItemMark( myMenus[Conn], scrn + FIRST_CNXN_ITEM, noMark);
  1186.     AdjustMenus();
  1187. }
  1188.  
  1189. void DoTheMenuChecks(void)
  1190. {
  1191.     short    active;
  1192.     short    windownum;
  1193.  
  1194.     if (TelInfo->numwindows>0)
  1195.         {
  1196.         EnableItem( myMenus[Conn],0);
  1197.         if (gApplicationPrefs->KeyPadAndFuncMenus) {            /* Baylor */
  1198.             EnableItem(myMenus[Keypad], 0);            /* Baylor */
  1199.             EnableItem(myMenus[Function], 0);        /* Baylor */
  1200.             }
  1201.         DrawMenuBar();
  1202.         }
  1203.  
  1204.     else 
  1205.         {
  1206.         DisableItem(myMenus[Conn],0);
  1207.         if (gApplicationPrefs->KeyPadAndFuncMenus) {            /* Baylor */
  1208.             DisableItem(myMenus[Keypad], 0);        /* Baylor */
  1209.             DisableItem(myMenus[Function], 0);        /* Baylor */
  1210.             }
  1211.         DrawMenuBar();
  1212.         }
  1213.  
  1214.     active =0;
  1215.     
  1216.     for (windownum=0;windownum<TelInfo->numwindows;windownum++)
  1217.         if (screens[windownum].active == CNXN_ACTIVE) active++;
  1218.         
  1219.     if (active<2)    
  1220.         DisableItem(myMenus[Conn],COnext);
  1221.     else EnableItem(myMenus[Conn],COnext);
  1222.  
  1223.     if (!active)
  1224.         {
  1225. /*        DisableItem(myMenus[Edit],EDcopy);
  1226.         DisableItem(myMenus[Edit],EDcopyt); */
  1227.         DisableItem(myMenus[Edit],EDpaste);
  1228.         DisableItem(myMenus[Emul],0);
  1229.         DrawMenuBar();
  1230.         }
  1231.     else 
  1232.         {
  1233. /*        EnableItem(myMenus[Edit],EDcopy);
  1234.         EnableItem(myMenus[Edit],EDcopyt); */
  1235.         EnableItem(myMenus[Edit],EDpaste);
  1236.         EnableItem( myMenus[Emul],0);
  1237.         DrawMenuBar();
  1238.         }
  1239. }
  1240.  
  1241.  
  1242.  
  1243. /*--------------------------------------------------------------------------*/
  1244. /* SetupMenusForSelection                                                    */
  1245. /* If there is a selection on screen, then let the user copy and print.        */
  1246. /* If not, then, oh well....just disable the menus and forget about it        */
  1247. /* ...and to think that this good stuff USED to be in rsmac.c.                 */
  1248. /* This is called from RSselect after the user clicks in the window, and     */
  1249. /* was moved here for modularity    - SMB                                    */
  1250. /*--------------------------------------------------------------------------*/
  1251. void SetMenusForSelection (short selected)                    /* NCSA: SB */    
  1252. {                                                            /* NCSA: SB */
  1253.     if (!selected)                                            /* NCSA: SB */
  1254.         {                                                    /* NCSA: SB */
  1255.         DisableItem(myMenus[Fil],FLprint);                    /* NCSA: SB */
  1256.         DisableItem(myMenus[Edit],EDcopy);                    /* NCSA: SB */
  1257.         DisableItem(myMenus[Edit],EDcopyt);                    /* NCSA: SB */
  1258.         }                                                    /* NCSA: SB */
  1259.     else                                                     /* NCSA: SB */
  1260.         {                                                    /* NCSA: SB */
  1261.         EnableItem(myMenus[Fil],FLprint);                    /* NCSA: SB */
  1262.         EnableItem(myMenus[Edit],EDcopy);                    /* NCSA: SB */
  1263.         EnableItem(myMenus[Edit],EDcopyt);                    /* NCSA: SB */
  1264.         }                                                    /* NCSA: SB */
  1265. }                                                            /* NCSA: SB */
  1266.  
  1267.  
  1268. long SetOtherFontSize(short currentSize)
  1269. {
  1270.     DialogPtr    dtemp;
  1271.     Str255 currentSizeStr, newSizeStr;
  1272.     long newSize;
  1273.     Boolean GoodValue;
  1274.     short ditem;
  1275.     
  1276.     dtemp=GetNewMyDialog( OtherFontDLOG, NULL, kInFront, (void *)ThirdCenterDialog); 
  1277.     InitCursor();
  1278.  
  1279.     GoodValue = 0;
  1280.     
  1281.     while (!GoodValue)
  1282.     {
  1283.         GoodValue = TRUE;
  1284.         NumToString((long) currentSize, currentSizeStr);
  1285.         SetTEText(dtemp, FontSizeTE, currentSizeStr);
  1286.     
  1287.         ditem = 0;
  1288.         while(ditem != DLOGOk && ditem != DLOGCancel)
  1289.             ModalDialog(DLOGwOK_CancelUPP, &ditem);
  1290.     
  1291.         if (ditem == DLOGCancel) {
  1292.             DisposeDialog( dtemp);
  1293.             return currentSize;
  1294.         }
  1295.     
  1296.         GetTEText(dtemp, FontSizeTE, newSizeStr);
  1297.         StringToNum(newSizeStr, &newSize);
  1298.     
  1299.         if (newSize < 9)
  1300.             GoodValue = FALSE;
  1301.         
  1302.         if (!GoodValue) SysBeep(4);
  1303.     }
  1304.     DisposeDialog( dtemp);
  1305.     
  1306.     return (newSize);
  1307. }
  1308. /*----------------------------------------------------------------------*/
  1309. /* NCSA: SB - SetColumnWidth                                            */
  1310. /*    Allow the user to FINALLY pick how many columns he wants on the     */
  1311. /*    screen.  Set up a dialog box to pick the # of columns, and then        */
  1312. /*    size-up the Telnet screen accordingly.  NOTE: The user still needs    */
  1313. /*     to do a "resize", unless he is using NAWS                            */
  1314. /*----------------------------------------------------------------------*/
  1315. void SetScreenDimensions(short scrn)
  1316. {
  1317.     DialogPtr    dtemp;
  1318.     Str255        ColumnsSTR, LinesSTR;
  1319.     long        columns, lines;
  1320.     short        ditem, notgood;
  1321.     
  1322.     dtemp=GetNewMyDialog( SizeDLOG, NULL, kInFront, (void *)ThirdCenterDialog); 
  1323.     
  1324.     SetCursor(theCursors[normcurs]);
  1325.  
  1326.     notgood = 1;
  1327.     lines = VSgetlines(screens[scrn].vs);
  1328.     columns = VSgetcols(screens[scrn].vs) + 1;
  1329.     
  1330.     while (notgood) {
  1331.         notgood = 0;                                /* Default to good */
  1332.         NumToString(columns, ColumnsSTR);
  1333.         NumToString(lines, LinesSTR);
  1334.         SetTEText(dtemp, ColumnsNumber, ColumnsSTR);
  1335.         SetTEText(dtemp, LinesNumber, LinesSTR);
  1336.         SelIText( dtemp, ColumnsNumber, 0, 32767);
  1337.     
  1338.         ditem = 3;
  1339.         while(ditem>2)
  1340.             ModalDialog(DLOGwOK_CancelUPP, &ditem);
  1341.     
  1342.         if (ditem == DLOGCancel) {
  1343.             DisposeDialog( dtemp);
  1344.             return;
  1345.             }
  1346.         
  1347.         GetTEText(dtemp, ColumnsNumber, ColumnsSTR);
  1348.         StringToNum(ColumnsSTR, &columns);
  1349.         GetTEText(dtemp, LinesNumber, LinesSTR);
  1350.         StringToNum(LinesSTR, &lines);
  1351.         
  1352.         if (columns < 10) {
  1353.             columns = 10;
  1354.             notgood = 1;
  1355.             }
  1356.         else if (columns > 132) {
  1357.             columns = 132;
  1358.             notgood = 1;
  1359.             }
  1360.  
  1361.         if (lines < 10) {
  1362.             lines = 10;
  1363.             notgood = 1;
  1364.             }
  1365.         else if (lines > 200) {
  1366.             lines = 200;
  1367.             notgood = 1;
  1368.             }
  1369.         
  1370.         if (notgood) SysBeep(4);
  1371.     }
  1372.     
  1373.     DisposeDialog( dtemp);
  1374.     
  1375.     VSsetlines( screens[scrn].vs, lines);
  1376.     RScalcwsize( screens[scrn].vs, columns);
  1377. /*    RSsize( screens[scrn].wind, NULL, 0); */
  1378.  
  1379.     if (screens[scrn].naws)
  1380.         SendNAWSinfo(&screens[scrn], (short)columns, (short)lines);
  1381.         
  1382.     updateCursor(1);
  1383. }
  1384.  
  1385. void    ChangeWindowName(WindowPtr    theWindow)
  1386. {
  1387.     DialogPtr    dptr;
  1388.     short        itemHit;
  1389.     Str255        theName;
  1390.  
  1391.     if( theWindow != NULL) {
  1392.         InitCursor();
  1393.         dptr = GetNewMySmallDialog(WinTitlDLOG, NULL, kInFront, (void *)ThirdCenterDialog );
  1394.  
  1395.         GetWTitle(theWindow, theName); 
  1396.         SetTEText( dptr, kWinNameTE, theName);
  1397.         SelIText( dptr, kWinNameTE, 0, 250 );
  1398.  
  1399.         itemHit = 0;
  1400.         while(itemHit != DLOGOk && itemHit != DLOGCancel)
  1401.             ModalDialog(DLOGwOK_CancelUPP, &itemHit);
  1402.         
  1403.         if(itemHit == DLOGOk) {
  1404.             GetTEText(dptr, kWinNameTE, theName);
  1405.             set_new_window_name(theName, theWindow);
  1406.             }
  1407.             
  1408.         DisposDialog(dptr);
  1409.         }
  1410. }
  1411.  
  1412. void    set_new_window_name(Str255 theName, WindowPtr theWindow)
  1413. {
  1414.     short    i;
  1415.     
  1416.     if(theName[0]) {
  1417.         i = WindowPtr2ScreenIndex(theWindow);
  1418.         if (i >= 0) {
  1419.             i += FIRST_CNXN_ITEM;
  1420.             SetWTitle(theWindow, theName);
  1421.             SetItem(myMenus[Conn], i, theName);
  1422.             }
  1423.         }
  1424. }
  1425.